<?php
App::uses('AppModel', 'Model');
/**
 * News Model
 *
 * @property Catenews $Catenews
 */
class News extends AppModel {

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';
	public $actsAs = array(
		'Uploader.Attachment' => array(
			// Do not copy all these settings, it's merely an example
			'image' => array(
				'name' => '',
				'tempDir' => TMP,
				'uploadDir' => 'files/uploads/news/',
				'baseDir' => 'files/uploads/news/',
				'prepend' => 'news_',
				'dbColumn' => 'image',
				'transforms' => array(
					'imageSmall' => array(
						'class' => 'resize',
						'append' => '_thumbnail',
						'prepend' => 'news_',
						'overwrite' => true,
						'width' => 150,
						'method' =>'resize',
						'height' => 120,
						'dbColumn' => 'imagesmall'
					)
				)
			)
		)
	);
	public $validate = array(
		'name' => array(
			'notEmpty' => array(
				'rule' => array('notEmpty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),

		'catenews_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

	public function beforeSave($options = array()) {
		$this->data[$this->alias]['users_id'] = AuthComponent::user('id');
		$this->data[$this->alias]['created_date'] = date("Y-m-d");
	}
	public $belongsTo = array(
		'Catenews' => array(
			'className' => 'Catenews',
			'foreignKey' => 'catenews_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Users' => array(
			'className' => 'Users',
			'foreignKey' => 'users_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
}
